package net.jsoft.pms.mapper.scs;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;

import com.github.pagehelper.Page;

import net.jsoft.pms.vo.scs.PublishService;
import net.jsoft.pms.vo.scs.Service;

@Mapper
@Component
public interface ServicesListMapper
{
    @Select("SELECT * FROM hx_sjmx.DZSWJ_YWFWQDB WHERE  REQUESTXSD IS NOT NULL AND RESPONSEXSD IS NOT NULL AND  DWFBZT IN(0,1,2,3,4,5,6)  ORDER BY SSZB  DESC ")
    List<Service> findAll();

    @SelectProvider(type = ServicesListProvider.class, method = "findFromDate")
    List<Service> findFromDate(@Param("date") String date);

    @SelectProvider(type = ServicesListProvider.class, method = "findByPageAndParms")
    Page<Service> findByPageAndParmsRtnBean(Object object, String string, String type);

    @Select("SELECT t.*, '' editNote,'' influence   FROM hx_sjmx.DZSWJ_YWFWQDB t WHERE  REQUESTXSD IS NOT NULL AND RESPONSEXSD IS NOT NULL AND  DWFBZT  IN( 1, 3,4 ) ORDER BY SSZB DESC ")
    List<Service> findPublicServices();

    @Select("SELECT t.* , '修改依据：     修改说明： ' editNote, '依赖关系：服务消费方需要同步升级；不同步升级无法校验通过。' influence  FROM hx_sjmx.DZSWJ_YWFWQDB  t WHERE  REQUESTXSD IS NOT NULL AND RESPONSEXSD IS NOT NULL AND  DWFBZT  IN( 3,4,5 )  ORDER BY SSZB DESC ")
    List<Service> addPublicServices();

    @InsertProvider(type = ServicesListProvider.class, method = "insertService")
    void insertService(@Param("list") List<Service> list, @Param("publishService") PublishService publishService, @Param("type") String type);

    @Insert("INSERT INTO HX_ZGXT.DZSWJ_ZHGLXT_SERVICELISTMAIN(ID,PUBLISHED_VERSION,PUBLISHED_DATE,NOTE) VALUES(#{id},#{version},#{publishDate},#{note })")
    void insertMain(PublishService publishService);

    @Select("SELECT * FROM  HX_ZGXT.DZSWJ_ZHGLXT_SERVICELISTMAIN")
    @Results(
    { @Result(column = "PUBLISHED_VERSION", property = "version", jdbcType = JdbcType.VARCHAR), @Result(column = "PUBLISHED_DATE", property = "publishDate", jdbcType = JdbcType.VARCHAR) })
    Page<PublishService> findPublishService();

    @Delete("DELETE FROM HX_ZGXT.DZSWJ_ZHGLXT_SERVICELISTMAIN WHERE ID = #{id}")
    int deleteMain(@Param("id") String id);

    @Delete("DELETE FROM HX_ZGXT.DZSWJ_ZHGLXT_SERVICELIST WHERE MAINID = #{id}")
    void deleteSub(String id);

    @Select("SELECT Y.YWFWID,Y.YWFWMC,Y.SSZB,Y.FWLJMS,Y.YWFWXH,Y.CZLX,Y.DWFBZT,Y.FWBBH,T.EDIT_NOTE EDITNOTE ,T.INFLUENCE FROM HX_ZGXT.DZSWJ_ZHGLXT_SERVICELIST T ,HX_SJMX.DZSWJ_YWFWQDB Y WHERE T.SERVICEID = Y.YWFWID AND MAINID = #{id} AND PUBLISHED_FLAG = 'all' ")
    List<Service> findPublicServicesById(String id);

    @Select("SELECT Y.YWFWID,Y.YWFWMC,Y.SSZB,Y.FWLJMS,Y.YWFWXH,Y.CZLX,Y.DWFBZT,Y.FWBBH,T.EDIT_NOTE EDITNOTE ,T.INFLUENCE FROM HX_ZGXT.DZSWJ_ZHGLXT_SERVICELIST T ,HX_SJMX.DZSWJ_YWFWQDB Y WHERE T.SERVICEID = Y.YWFWID AND MAINID = #{id} AND PUBLISHED_FLAG = 'add' ")
    List<Service> addPublicServicesById(String id);

    @Select("SELECT * FROM HX_ZGXT.DZSWJ_ZHGLXT_SERVICELISTMAIN WHERE ID = #{id}")
    @Results(
    { @Result(column = "PUBLISHED_VERSION", property = "version", jdbcType = JdbcType.VARCHAR), @Result(column = "PUBLISHED_DATE", property = "publishDate", jdbcType = JdbcType.VARCHAR) })
    PublishService findPublishServiceById(String id);

}
